package com.penghaisoft.microwms.producthand.web.controller.intowarehouse;

import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.wms.model.MsbarCode;
import com.penghaisoft.microwms.product.service.IMsbarCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/msbarcode")
@Slf4j
public class MsbarCodeController extends BaseController {

    @Autowired
    private IMsbarCodeService msbarCodeService;

    /**
     * 新增记录
     *
     * @param msbarCode
     * @return
     */
    @PostMapping("c")
    public TransResult create(MsbarCode msbarCode) {
        msbarCode.preInsert();
        Resp resp = msbarCodeService.create(msbarCode);
        return fromResp(resp);
    }

    /**
     * 删除记录（逻辑删除active_flag=0)
     *
     * @param msbarCode
     * @return
     */
    @PostMapping("d")
    public TransResult delete(MsbarCode msbarCode) {
        msbarCode.preUpdate();
        Resp resp = msbarCodeService.delete(msbarCode);
        return fromResp(resp);
    }

    /**
     * 查询列表
     *
     * @param pager
     * @return
     */
    @PostMapping("list")
    public TransResult list(@RequestParam(name = "page", defaultValue = "1") int page,
                            @RequestParam(name = "rows", defaultValue = "10") int rows, MsbarCode msbarCode) {
        Pager<MsbarCode> result = msbarCodeService.findListByCondition(page, rows, msbarCode);
        return success(result);
    }

    /**
     * 查询单条
     *
     * @param id
     * @return
     */
    @GetMapping("r/{id}")
    public TransResult queryById(@PathVariable String id) {
        MsbarCode msbarCode = msbarCodeService.findById(id);
        return success(msbarCode);
    }

    /**
     * 修改记录
     *
     * @param msbarCode
     * @return
     */
    @PostMapping("u")
    public TransResult update(MsbarCode msbarCode) {
        msbarCode.preUpdate();
        Resp resp = msbarCodeService.update(msbarCode);
        return fromResp(resp);
    }

}
